var app = getApp(), until = require("../../utils/util.js");

Page({
    data: {
        people: 9,
        erweima: "",
        haibaobj: "",
        t_status: !1,
        current: 0,
        region: [],
        index:0,
        array: [],
        bgimage: "/hyb_jianzhi/images/agenttop.png",
        btmimage: "/hyb_jianzhi/images/agentbtm.png",
        businessDistrict:[],
        businessIndex:0,
        cityId:''
    },
    getform: function(t) {
        console.log(t), app.util.request({
            url: "entry/wxapp/Formid",
            data: {
                openid: wx.getStorageSync("openid"),
                formid: t
            },
            success: function(t) {}
        });
    },
    saveimg: function(t) {
        var e = this;
        wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            canvasId: t,
            success: function(a) {
                wx.showModal({
                    title: "提示",
                    content: "确定保存该图片",
                    success: function(t) {
                        t.confirm && wx.saveImageToPhotosAlbum({
                            filePath: a.tempFilePath,
                            success: function(t) {
                                wx.showToast({
                                    title: "保存成功"
                                }), setTimeout(function() {
                                    e.setData({
                                        t_status: !1,
                                        t_status2: !1
                                    });
                                }, 1e3);
                            }
                        });
                    }
                });
            }
        });
    },
    onLoad: function(t) {
        var self = this;
        // 加载代理区域
         self.loadAgentArea();
    },
    loadAgentArea:function(){
        var self = this;
         app.util.request({
            url: "entry/wxapp/Getshangquan",
            data: {
                id: 0,
            },
            success: function(n) {
                console.log("城市"+JSON.stringify(n))
                self.setData({
                    array:n.data.data
                })
            }
        });
         
    },
     // 获取用户名
    userNameInput: function (e) {
      var self = this; 
      self.setData({
         userName: e.detail.value
       })
     },
     // 获取手机号
    userPhoneInput:function(e){
      var self = this;
       self.setData({
        userPhone: e.detail.value
       })
     },
    // 提交申请代理接口
    formAgent:function(){
         var self = this;
         if(self.data.businId == ''){
            self.setData({
                businId:0
            })
         }
         app.util.request({
            url: "entry/wxapp/Postshangquan",
            data: {
                openid : wx.getStorageSync("openid"),
                cityid:self.data.cityId,
                id:self.data.businId,
                name:self.data.userName,
                mobile:self.data.userPhone
            },
            success: function(n) {
                wx.showToast({
                   title: '申请成功!请耐心等待审核。'
                });
                setTimeout(function(){
                     wx.reLaunch({
                        url: "/hyb_jianzhi/index/index"
                    });
                },500)
            }
        });
    },
     bindRegionChange: function(a) {
        var self = this;
         self.setData({
            index: a.detail.value
         });
         self.setData({
           cityId: self.data.array[self.data.index].id
         });
         console.log("picker发送选择改变，携带值为", self.data.cityId);
         app.util.request({
            url: "entry/wxapp/Getshangquan",
            data: {
                id: self.data.cityId,
            },
            success: function(n) {
                console.log("商圈"+JSON.stringify(n))
                self.setData({
                    businessDistrict:n.data.data
                })
            }
        });
    },
    bindBusinessChange:function(a){
        var self = this;
         self.setData({
            businessIndex: a.detail.value
        });
        self.setData({
           businId: self.data.businessDistrict[self.data.businessIndex].id
         });
        console.log("picker发送选择改变，携带值为", self.data.businId);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});